package io.renren.modules.sp.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.annotation.LogOperation;
import io.renren.common.utils.QrCodeCreateUtil;
import io.renren.common.utils.Result;
import io.renren.common.utils.image.ImageTool;
import io.renren.modules.sp.entity.AllContentEntity;
import io.renren.modules.sp.entity.SpMatchItemTeamUserEntity;
import io.renren.modules.sp.service.SpMatchItemTeamUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
* 用户地区
*
* @author Mark sunlightcs@gmail.com
* @since 3.0 2022-06-12
*/
@RestController
@RequestMapping("sp/tools")
@Api(tags="用户地区")
public class SpToolsController {

    @Autowired
    private SpMatchItemTeamUserService spMatchItemTeamUserService;

    /**
     * 证书二维码生成
     * @return
     */
    @GetMapping("cerTools")
    @ApiOperation("信息")
    @LogOperation("证书二维码生成")
    public Result<String> cerTools(@RequestBody Map<String, Object> params) throws Exception {
        String no = (String)params.get("no");
        String bgPic = (String)params.get("bgPic");
        String ercode = QrCodeCreateUtil.genGR("http://login.int-ede.com/renren-admin/front/spuser/t/" + no);
        AllContentEntity all = ImageTool.rongyu_linshi(no ,ercode, bgPic);
        String url = ImageTool.drawList(all);

        List<SpMatchItemTeamUserEntity> list = spMatchItemTeamUserService.queryTicketBy(
                new QueryWrapper<SpMatchItemTeamUserEntity>().eq("certificate", no)
        );
        if(list.size() > 0){
            SpMatchItemTeamUserEntity entity = list.get(0);
            entity.setCertificateUrl(url);
            spMatchItemTeamUserService.updateById(entity);
        }
        return new Result<String>().ok(url);
    }

}